unit CheckFifo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, BaseDialog, cxGraphics, cxLookAndFeels, cxLookAndFeelPainters,
  Menus, cxControls, cxContainer, cxEdit, dxSkinsCore,
  dxSkinsDefaultPainters, cxStyles, dxSkinscxPCPainter,
  cxDataStorage, DB, cxDBData, cxGridLevel, cxClasses,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, cxLabel, StdCtrls, ExtCtrls,
  MisString,
  DBAccess, Uni, dxSkinsForm, cxNavigator, cxCustomData, cxFilter, cxData,
  MemDS, cxButtons;

type
  TfrmCheckFifo = class(TfrmBaseDialog)
    cxLabel1: TcxLabel;
    ViewFifo: TcxGridDBTableView;
    LevelFifo: TcxGridLevel;
    grdFifo: TcxGrid;
    dsFifo: TDataSource;
    qryFifo: TUniQuery;
    qryFifodepotid: TIntegerField;
    qryFifoproductid: TIntegerField;
    qryFifobname: TStringField;
    qryFifobcode: TStringField;
    qryFifodepotname: TWideStringField;
    qryFifop_code: TStringField;
    qryFifop_name: TWideStringField;
    qryFifoeqty: TFloatField;
    ViewFifobname: TcxGridDBColumn;
    ViewFifobcode: TcxGridDBColumn;
    ViewFifodepotname: TcxGridDBColumn;
    ViewFifop_code: TcxGridDBColumn;
    ViewFifop_name: TcxGridDBColumn;
    ViewFifoeqty: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCheckFifo: TfrmCheckFifo;

function CheckFifoNeg(dtAcc, dtNext: TDateTime): Boolean;

implementation

{$R *.dfm}

function CheckFifoNeg(dtAcc, dtNext: TDateTime): Boolean;
begin
  frmCheckFifo := TfrmCheckFifo.Create(nil);
  try
    frmCheckFifo.qryFifo.Params.ParseSQL(frmCheckFifo.qryFifo.SQL.Text, true);
    frmCheckFifo.qryFifo.Params.ParamByName('begindate').Value := dtAcc;
    frmCheckFifo.qryFifo.Params.ParamByName('enddate').Value := dtNext;
    frmCheckFifo.qryFifo.Open;
  except
    on E: Exception do
    begin
      ShowErrorBox(E.Message);
      FreeAndNil(frmCheckFifo);
      Result := False;
      Exit;
    end;
  end;
  Result := frmCheckFifo.qryFifo.RecordCount = 0;
  if (frmCheckFifo.qryFifo.RecordCount > 0) then
    frmCheckFifo.ShowModal();
  FreeAndNil(frmCheckFifo);
end;

procedure TfrmCheckFifo.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  if qryFifo.Active then
    qryFifo.Close;
end;

end.

